package com.neuedu.his.controller;


import com.neuedu.his.entity.InspectItem;
import com.neuedu.his.framework.PageInfo;
import com.neuedu.his.framework.annotation.MethodAlias;
import com.neuedu.his.framework.servlet.BaseServlet;
import com.neuedu.his.service.InspectItemService;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;

/**
 * 项目：      his
 * 类名:       UserController
 * 创建时间：  2020/12/22  11:05
 * 描述 :
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */
@WebServlet(name = "InspectItemController", urlPatterns = "/inspect_item")
public class InspectItemController extends BaseServlet {

    private InspectItemService inspectItemService = new InspectItemService();


    public void listAll(HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<InspectItem> list = inspectItemService.queryList(request);

        //将结果以json格式返回
        this.success(response, list);
    }

    @MethodAlias("query")
    public void list(HttpServletRequest request, HttpServletResponse response) throws IOException {

        PageInfo pageInfo = inspectItemService.queryListByPage(request);
        //将结果以json格式返回

        this.success(response, pageInfo);
    }


    public void save(HttpServletRequest request, HttpServletResponse response) throws ParseException, NoSuchFieldException, IllegalAccessException, InstantiationException, IOException {
        InspectItem checkItem = parseParameter(request, InspectItem.class);

        boolean success = false;
        if (checkItem.getId() != null) { //修改
            success = inspectItemService.update(checkItem);
        } else { //添加
            success = inspectItemService.save(checkItem);
        }

        super.success(response, success);
    }

    public void toEdit(HttpServletRequest request, HttpServletResponse response) throws ParseException, NoSuchFieldException, IllegalAccessException, InstantiationException, IOException {

        String id = request.getParameter("id");

        InspectItem checkItem = inspectItemService.queryById(Integer.parseInt(id));

        super.success(response, checkItem);
    }


    public void del(HttpServletRequest request, HttpServletResponse response) throws ParseException, NoSuchFieldException, IllegalAccessException, InstantiationException, IOException {

        String id = request.getParameter("id");

        boolean success = inspectItemService.deleteById(Integer.parseInt(id));

        super.success(response, success);
    }
}